﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form3 : Form
    {
        private gjpingyi gjpy;

        public Form3()
        {
            InitializeComponent();
            // 隐藏 DataGridView 的行头
            dataGridView1.RowHeadersVisible = false;
            dGVMarkPoint.RowHeadersVisible = false;
            gjpy = new gjpingyi();
            dGVMarkPoint.RowsAdded += dGVMarkPoint_RowsAdded;
        }
        public void UpdateDataGrid(string[] data)
        {
            if (InvokeRequired)
            {
                Invoke(new Action<string[]>(UpdateDataGrid), data);
            }
            else
            {
                if (dGVMarkPoint != null)
                {
                    dGVMarkPoint.Rows.Clear();
                    dGVMarkPoint.Rows.Add(data); // 将数据直接添加到 DataGridView 的行中
                }
                else
                {
                    MessageBox.Show("DataGridView 未初始化。");
                }
            }
        }
        private void dGVMarkPoint_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            // 清空 dGVRotation 中的旧数据
            dataGridView1.Rows.Clear();

            // 获取新添加的行
            for (int i = e.RowIndex; i < e.RowIndex + e.RowCount; i++)
            {
                DataGridViewRow row = dGVMarkPoint.Rows[i];

                // 确保行中有 θ 数据
                if (row.Cells["offsetheta"].Value != null)
                {
                    double dX = Convert.ToDouble(row.Cells["offsetX"].Value);
                    double dy = Convert.ToDouble(row.Cells["offsetY"].Value);
                    double theta = Convert.ToDouble(row.Cells["offsetheta"].Value);

                    
                    // 计算所有固定点的旋转结果
                    var rotatedPoint = gjpy.RotateAndTranslateFixedPoints(theta, dX, dy, clockwise: false);


                    foreach (var point in rotatedPoint)
                    {
                        dataGridView1.Rows.Add(point.Item1, point.Item2);
                    }
                }
            }
        }
        private void dGVMarkPoint_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void Form3_Load(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
        }
    }
}
